<!DOCTYPE html>
<html>
  <head lang="en">
    <meta charset="UTF-8"/>
    <meta name="msapplication-tap-highlight" content="no"/>
    <meta name="viewport" content="user-scalable=no, initial-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi"/>
    <title>Testing IndexedDB Shim</title>

    <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon" />
    <link rel="stylesheet" href="../node_modules/mocha/mocha.css"/>
    <link rel="stylesheet" href="styles.css"/>
  </head>
  <body>
    <div id="mocha">
      <ul id="supports">
        <li id="supports-websql" class="test">WebSql</li>
        <li id="supports-indexeddb" class="test">IndexedDB</li>
        <li id="supports-mozindexeddb" class="test">mozIndexedDB</li>
        <li id="supports-webkitindexeddb" class="test">webkitIndexedDB</li>
        <li id="supports-msindexeddb" class="test">msIndexedDB</li>
      </ul>
      <div id="options">
        <a id="use-native" href="?useShim=false">Switch to Native IndexedDB</a>
        <a id="use-shim" href="?useShim=true">Switch to IndexedDBShim</a>
      </div>
      <div id="choke-warning">
        <h1>Warning!</h1>
        <ul>
          <li class="test fail">
            <h2>
              This browser has trouble running the <strong>hundreds</strong> of tests on this page.
              If you get test failures, then try running each test suite separately, by clicking the test suite's title.
            </h2>
          </li>
        </ul>
      </div>
    </div>

    <!-- Test Environment -->
    <script src="../node_modules/mocha/mocha.js"></script>
    <script src="../node_modules/chai/chai.js"></script>
    <script src="../node_modules/sinon/pkg/sinon.js"></script>
    <script src="test-environment.js"></script>
    <script src="test-utils.js"></script>

    <script src="cordova.js"></script>
    <script>
        /* eslint-env mocha */
        document.addEventListener('deviceready', onDeviceReady, false);

        /**
         * Injects scripts when device is ready.
         * @returns {void}
         */
        function onDeviceReady () {
            addScript('api-spec.js');
            addScript('IDBFactory/cmp-spec.js');
            addScript('IDBFactory/deleteDatabase-spec.js');
            addScript('IDBFactory/open-spec.js');
            addScript('IDBDatabase/close-spec.js');
            addScript('IDBDatabase/createObjectStore-spec.js');
            addScript('IDBDatabase/deleteObjectStore-spec.js');
            addScript('IDBDatabase/transaction-spec.js');
            addScript('IDBIndex/count-spec.js');
            addScript('IDBIndex/get-spec.js');
            addScript('IDBIndex/getKey-spec.js');
            addScript('IDBIndex/openCursor-spec.js');
            addScript('IDBObjectStore/add-spec.js');
            addScript('IDBObjectStore/put-spec.js');
            addScript('IDBObjectStore/add-put-spec.js');
            addScript('IDBObjectStore/clear-spec.js');
            addScript('IDBObjectStore/createIndex-spec.js');
            addScript('IDBObjectStore/deleteIndex-spec.js');
            addScript('IDBObjectStore/delete-spec.js');
            addScript('IDBObjectStore/index-spec.js');
            addScript('IDBTransaction/objectStore-spec.js');
            addScript('IDBTransaction/events-spec.js');

            setTimeout(runTests, 2000);
        }

        /**
         * Begins Mocha tests.
         * @returns {void}
         */
        function runTests () {
            mocha.checkLeaks();
            mocha.run();
        }

        /**
         * Injects a script.
         * @param {string} url
         * @returns {void}
         */
        function addScript (url) {
            const scriptElem = document.createElement('script');
            scriptElem.src = url;
            document.head.append(scriptElem);
        }
    </script>
  </body>
</html>
